
* Table 7 
* Health spending by source
qui{
clear 
use "Counterfactuals Stata Files/Counterfactual16.dta"
replace experiment=0 if experiment==16
append using "Counterfactuals Stata Files/Counterfactual14.dta"
keep if age<65

*generate table as follows:
*total MC*.6 / person
*total MC*6 if treated / person 
* paid by OOP/person 
* paid by ESHI
* paid by Public 
* Unpaid


* OOP paid by individuals
gen col3= OOP if tr_pay_alt==1 
replace col3=OOP if type2==1 & govt_transfer==0  
replace col3= OOP-govt_transfer if govt_transfer<OOP & govt_transfer>0 & tr_pay_alt==2

* What ESHI pays
gen col4= MC*.6 - OOP if I_treat==1 & ESHI==1 


* Public: Medicaid and DI (not the Universal Health insurance)
gen col5=OOP  if tr_pay_alt==2 
* Medicaid only pays some of OOP when the person can afford the rest
replace col5 =  govt_transfer if govt_transfer<OOP &  tr_pay_alt==2

* Unpaid bills
gen col6 =OOP if tr_pay_alt==3 


* Costs if all treated
gen col7=OOP if tr_pay_alt==4 & experiment==0 & ESHI==0 
replace col7=MC_orig*.6 if tr_pay_alt==4 & experiment==0 & ESHI==1  
replace col7=MC_orig*.6  if tr_pay_alt==4 & experiment==14 

* Universal health insurance 
gen col8=MC_orig *.6 - OOP if ((I_treat==1 & ESHI==0) | (type2==1 & ESHI==0 ) ) & experiment==14
gen col9=MC_orig *.6 - OOP if (I_treat==1 & ESHI==0)  & experiment==14

gen count=1

* Calculate statistics for all, for benchmark and UHI experiment
preserve
collapse (sum) col*  count, by(experiment)
replace col3=col3/count
replace col4=col4/count
replace col5=col5/count
replace col6=col6/count
replace col7=col7/count
replace col8=col8/count
replace col9=col9/count
drop count
save "Temp/Bills_All_exp.dta", replace
restore

* Calculate statistics by ESHI/ No ESHI groups
collapse (sum) col*  count, by(experiment ESHI)
replace col3=col3/count
replace col4=col4/count
replace col5=col5/count
replace col6=col6/count
replace col7=col7/count
replace col8=col8/count
replace col9=col9/count

drop count
append using "Temp/Bills_All_exp.dta"

label var col3 "OOP (Self)"
label var col4 "ESHI"
label var col5 "Medicaid"
label var col6 "Unpaid"
label var col7 "Untreated"
label var col8 "Public Insurance"
label var col9 "Public Insurance - No Preventive"

gen total= col3 + col4 + col5 + col6 if experiment==0
replace total= col3 + col4 + col5 + col6 + col8 if experiment==14
label var total "Total if treated"

replace ESHI = 2 if ESHI==.
label define eshi_new 0 "No ESHI" 1 "ESHI" 2 "All"
label values ESHI eshi_new


table  (ESHI experiment) ,  statistic(mean col3 col4 col5 col6 col8 col9 total col7)  nototals nformat(%5.0f)  

collapse (mean) col3 col4 col5 col6 col8 col9 total col7, by (ESHI experiment)
sort experiment ESHI 
drop col9
order experiment ESHI  total col3 col4 col5 col6 col8  col7

* Open data and copy paste in Table 7. All columns and rows are in order
}


* Table 130 in appendix: same as Table 7 in paper but only HS or Less to compare with racial minorities
* Health spending by source
qui{
clear 
use "Counterfactuals Stata Files/Counterfactual16.dta"
replace experiment=0 if experiment==16
append using "Counterfactuals Stata Files/Counterfactual14.dta"
keep if age<65
keep if education==1
*generate table as follows:
*total MC*.6 / person
*total MC*6 if treated / person 
* paid by OOP/person 
* paid by ESHI
* paid by Public 
* Unpaid


* OOP paid by individuals
gen col3= OOP if tr_pay_alt==1 
replace col3=OOP if type2==1 & govt_transfer==0  
replace col3= OOP-govt_transfer if govt_transfer<OOP & govt_transfer>0 & tr_pay_alt==2

* What ESHI pays
gen col4= MC*.6 - OOP if I_treat==1 & ESHI==1 


* Public: Medicaid and DI (not the Universal Health insurance)
gen col5=OOP  if tr_pay_alt==2 
* Medicaid only pays some of OOP when the person can afford the rest
replace col5 =  govt_transfer if govt_transfer<OOP &  tr_pay_alt==2

* Unpaid bills
gen col6 =OOP if tr_pay_alt==3 


* Costs if all treated
gen col7=OOP if tr_pay_alt==4 & experiment==0 & ESHI==0 
replace col7=MC_orig*.6 if tr_pay_alt==4 & experiment==0 & ESHI==1  
replace col7=MC_orig*.6  if tr_pay_alt==4 & experiment==14 

* Universal health insurance 
gen col8=MC_orig *.6 - OOP if ((I_treat==1 & ESHI==0) | (type2==1 & ESHI==0 ) ) & experiment==14
gen col9=MC_orig *.6 - OOP if (I_treat==1 & ESHI==0)  & experiment==14

gen count=1

* Calculate statistics for all, for benchmark and UHI experiment
preserve
collapse (sum) col*  count, by(experiment)
replace col3=col3/count
replace col4=col4/count
replace col5=col5/count
replace col6=col6/count
replace col7=col7/count
replace col8=col8/count
replace col9=col9/count
drop count
save "Temp/Bills_All_exp.dta", replace
restore

* Calculate statistics by ESHI/ No ESHI groups
collapse (sum) col*  count, by(experiment ESHI)
replace col3=col3/count
replace col4=col4/count
replace col5=col5/count
replace col6=col6/count
replace col7=col7/count
replace col8=col8/count
replace col9=col9/count

drop count
append using "Temp/Bills_All_exp.dta"

label var col3 "OOP (Self)"
label var col4 "ESHI"
label var col5 "Medicaid"
label var col6 "Unpaid"
label var col7 "Untreated"
label var col8 "Public Insurance"
label var col9 "Public Insurance - No Preventive"

gen total= col3 + col4 + col5 + col6 if experiment==0
replace total= col3 + col4 + col5 + col6 + col8 if experiment==14
label var total "Total if treated"

replace ESHI = 2 if ESHI==.
label define eshi_new 0 "No ESHI" 1 "ESHI" 2 "All"
label values ESHI eshi_new


table  (ESHI experiment) ,  statistic(mean col3 col4 col5 col6 col8 col9 total col7)  nototals nformat(%5.0f)  

collapse (mean) col3 col4 col5 col6 col8 col9 total col7, by (ESHI experiment)
sort experiment ESHI 
drop col9
order experiment ESHI  total col3 col4 col5 col6 col8  col7

* Open data and copy paste in Table 130 in appendix. All columns and rows are in order
}

